/*
 * @Autor: suiqingying
 * @Date: 2020-11-17 18:38:50
 * @LastEditors: suiqingying
 * @LastEditTime: 2020-11-18 18:59:29
 */
#include <bits/stdc++.h>
inline int read()
{
    register int x = 0, f = 1;
    register char c = getchar();
    while (!isdigit(c))
    {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (isdigit(c))
    {
        x = x * 10 + c - '0', c = getchar();
    }
    return x * f;
}
const int maxn = 2e5 + 10;
int tot, head[maxn], nxt[maxn << 1], ver[maxn << 1];
void add(int u, int v)
{
    ver[++tot] = v;
    nxt[tot] = head[u];
    head[u] = tot;
}
int c[maxn];
int rt1, rt2;
namespace GetDiameter
{
    int maxdep = 0;
    void dfs(int x, int fa, int dep)
    {
        if (dep > maxdep)
        {
            rt2 = x;
            maxdep = dep;
        }
        for (int i = head[x]; i; i = nxt[i])
        {
            register int y = ver[i];
            if (y == fa)
            {
                continue;
            }
            dfs(y, x, dep + 1);
        }
    }
    inline void work()
    {
        dfs(1, 0, 1);
        rt1 = rt2, maxdep = 0;
        dfs(rt1, 0, 1);
    }
} // namespace GetDiameter
int ans[maxn], cnt[maxn];
int depth[maxn], md1[maxn], md2[maxn], son[maxn];
void dfs1(int x, int fa)
{
    depth[x] = depth[fa] + 1;
    md1[x] = md2[x] = son[x] = 0;
    for (register int i = head[x]; i; i = nxt[i])
    {
        register int y = ver[i];
        if (y == fa)
        {
            continue;
        }
        dfs1(y, x);
        if (md1[y] > md1[x])
        {
            md2[x] = md1[x];
            md1[x] = md1[y];
            son[x] = y;
        }
        else if (md1[y] > md2[x])
        {
            md2[x] = md1[y];
        }
    }
    if (!son[x])
    {
        md1[x] = depth[x];
    }
}
inline void addx(register int x)
{
    cnt[c[x]]++;
    if (cnt[c[x]] == 1)
    {
        cnt[0]++;
    }
}
int top, s[maxn];
inline void delx(register int x)
{
    cnt[c[x]]--;
    if (cnt[c[x]] == 0)
    {
        cnt[0]--;
    }
    // if(cnt[c[s.top()]])
    top--;
}
void dfs2(int x, int fa)
{
    if (fa)
    {
        s[++top] = fa;
        addx(fa);
    }
    while (top && depth[x] - depth[s[top]] <= md2[x] - depth[x])
    {
        // <
        delx(s[top]);
    }
    if (son[x])
    {
        dfs2(son[x], x);
    }
    //ans[x] = std::max(ans[x], cnt[0]);
    while (top && depth[x] - depth[s[top]] <= md1[x] - depth[x])
    {
        delx(s[top]);
    }
    ans[x] = std::max(ans[x], cnt[0]);
    for (register int i = head[x]; i; i = nxt[i])
    {
        register int y = ver[i];
        if (y == fa || y == son[x])
        {
            continue;
        }
        dfs2(y, x);
    }
    if (fa && top && s[top] == fa)
    {
        delx(s[top]);
    }
}
inline void solve(register int rt)
{
    dfs1(rt, 0), dfs2(rt, 0);
}
int main()
{
    //    freopen("1.in", " r", stdin);
    register int n = read(), m = read();
    for (register int i = 1; i < n; ++i)
    {
        register int x = read(), y = read();
        add(x, y), add(y, x);
    }
    for (register int i = 1; i <= n; ++i)
    {
        c[i] = read();
    }
    GetDiameter::work();
    solve(rt1), solve(rt2);
    for (register int i = 1; i <= n; ++i)
    {
        printf("%d\n", ans[i]);
    }
    return 0;
}
